import express from 'express'
import router from './router.js'
import http from 'http'
import cookieParser from 'cookie-parser'
import bodyParser from 'body-parser'
import socket from './socket.js'
import template from 'express-art-template';

var app = express();
var httpServer = http.createServer(app);

socket(httpServer);

app.engine('html', template);
// 开放静态资源
app.use('/public/', express.static('./public/'));
app.use('/uploads/', express.static('./uploads/'));

// 解析 application/json
app.use(bodyParser.json()); 
// 解析 application/x-www-form-urlencoded
app.use(bodyParser.urlencoded());

app.use(cookieParser('web-socket')); //使用cookie中间件，传入签名123456进行加密

// 使用路由
app.use(router);

httpServer.listen(3000, () => {
  console.log('http server running 3000')
})